Avoid integer overflow in gdk_rectangle_intersect
authorAlexander Larsson <alexl@redhat.com>
Fri, 22 Jan 2010 08:34:57 +0000 (09:34 +0100)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Sun, 4 Apr 2010 00:55:23 +0000 (20:55 -0400)
commitb8a0ff9e0434a3fba6e8e126fe3d0fa6851d7c6d
tree35bb2fd02b4477a8f0043f6ae622d2af75af7a45
parentc81131ff2195566cc7375c6df81a3f2cbcd03508
Avoid integer overflow in gdk_rectangle_intersect

If e.g. the right edge of the leftmost rectangle is near MIN_INT, and
the left edge of the rightmost rectangle is large then subtracting these
can lead to an integer overflow, making the resultant "width" falsely
positive, thus returning a very wide result instead of the expected
no-intersection result.

We avoid the overflow by not doing the subtraction unless we know the
result will be positive. There are still risks for overflow if x + width
or y + width is larger than MAXINT, but we won't ever overflow for valid
rects now.

This may fix #607687
gdk/gdkrectangle.c